/*
给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
输入：head = [1,2,3,4,5]
输出：[5,4,3,2,1]
*/
package main

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
type ListNode struct {
 Val int
 Next *ListNode
}
func reverseList(head *ListNode) *ListNode {
	if head == nil {
		return head
	}

	var newHead *ListNode
	p := head

	for p != nil{
		next := p.Next
		p.Next = newHead
		newHead = p
		p = next
	}
	return newHead
}